<?php

/**
 * This is the model class for table "form_element".
 *
 * The followings are the available columns in table 'form_element':
 * @property integer $id
 * @property string $form_id
 * @property string $title
 * @property string $guidelines
 * @property string $size
 * @property integer $is_required
 * @property integer $is_unique
 * @property integer $is_private
 * @property string $type
 * @property integer $position
 * @property string $default_value
 * @property string $constraint
 * @property integer $total_child
 */
class FormElementBase extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return FormElement the static model class
	 */
	public static function model($className='FormElement')
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return SITE_TABLE_PREFIX.'form_element';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('is_required, is_unique, is_private, position, total_child', 'numerical', 'integerOnly'=>true),
			array('size', 'length', 'max'=>6),
			array('type, constraint', 'length', 'max'=>50),
			array('form_id, title, guidelines, default_value', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, form_id, title, guidelines, size, is_required, is_unique, is_private, type, position, default_value, constraint, total_child', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'form_id' => 'Form',
			'title' => 'Title',
			'guidelines' => 'Guidelines',
			'size' => 'Size',
			'is_required' => 'Is Required',
			'is_unique' => 'Is Unique',
			'is_private' => 'Is Private',
			'type' => 'Type',
			'position' => 'Position',
			'default_value' => 'Default Value',
			'constraint' => 'Constraint',
			'total_child' => 'Total Child',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('form_id',$this->form_id,true);
		$criteria->compare('title',$this->title,true);
		$criteria->compare('guidelines',$this->guidelines,true);
		$criteria->compare('size',$this->size,true);
		$criteria->compare('is_required',$this->is_required);
		$criteria->compare('is_unique',$this->is_unique);
		$criteria->compare('is_private',$this->is_private);
		$criteria->compare('type',$this->type,true);
		$criteria->compare('position',$this->position);
		$criteria->compare('default_value',$this->default_value,true);
		$criteria->compare('constraint',$this->constraint,true);
		$criteria->compare('total_child',$this->total_child);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
}